<template>
  <div class="demo-pagination-block">
    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="pageSizes"
      :small="false"
      :background="false"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentPage"
    />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
interface Props {
  total: number
  pageSizes?: any[]
}
const props = withDefaults(defineProps<Props>(), {
  pageSizes: () => [5, 10, 20, 30]
})
const currentPage = ref(1)
const pageSize = ref(10)
const emit = defineEmits(['handleSizeChange', 'handleCurrentPage'])
const handleSizeChange = (val: number) => {
  // 控制每页条数
  console.log(`每页条数为 ${val}`)
  emit('handleSizeChange', val)
}
const handleCurrentPage = (val: number) => {
  // 控制页码
  console.log(`目前在第: ${val}页`)
  emit('handleCurrentPage', val)
}
</script>

<style lang="less" scoped></style>
